package com.myApp.rss;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * RSSItem的添加
 */
public class RSSFeed {

	private String title = null; 
	private String pubdate = null;
	public String getPubdate() {
		return pubdate;
	}

	public void setPubdate(String pubdate) {
		this.pubdate = pubdate;
	}

	private int itemCount; //新闻数
	private List<RSSItem> itemList; 
	
	
	public RSSFeed() {
		itemList = new ArrayList<RSSItem>();
	}
	
	/**
	 * 添加项
	 * @param item
	 * @return
	 */
	public int addItem(RSSItem item) {
		itemList.add(item);
		itemCount ++;
		return itemCount;
	}
	
	public RSSItem getItem(int location) {
		return itemList.get(location);
	}
	
	/**
	 * 返回所有RSS的列表
	 * @return
	 */
	public List<RSSItem> getAllItems() {
		return itemList;
	}
	
	/**
	 * 取得供新闻一览使用的itemList
	 * 
	 * @param channelName 频道名称
	 * @return itemList
	 */
	public List<Map<String,Object>> getAllItemsForListView(String channelName) {
		List<Map<String,Object>> data = new ArrayList<Map<String,Object>>();
		int size = itemList.size();
		
		String channelLabel = "频道：" + channelName;
		
		for(int i=0 ;i<size; i++) {
			HashMap<String,Object> item = new HashMap<String,Object>();
			item.put(RSSItem.TITLE, itemList.get(i).getTitle()); 
			item.put(RSSItem.PUBDATE, itemList.get(i).getPubDate());
			item.put(RSSItem.CHANNEL, channelLabel);
			data.add(item);
		}
		return data;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	public int getItemCount() {
		return itemCount;
	}
}
